Android的SQLite基本操作
whereClause1, name, +[phoneNumber] VARCHAR NOT NULL);private DBHelper db;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);createView();setListener();}private void createView(){createDatabase = (Button) findViewById(R.id.createDatabase);createTable = (Button) findViewById(R.id.createTable);insert = (Button) findViewById(R.id.insert);select = (Button) findViewById(R.id.select);update = (Button) findViewById(R.id.update);delete = (Button) findViewById(R.id.delete);}//加监听器private void setListener(){createDatabase.setOnClickListener(this);createTable.setOnClickListener(this);insert.setOnClickListener(this);select.setOnClickListener(this);update.setOnClickListener(this);delete.setOnClickListener(this);}//各种监听方法@Overridepublic void onClick(View view) {switch(view.getId()){case R.id.createDatabase:{db = new DBHelper(MainActivity.this, null, version);}/* * 当第一次创建数据库时,1);mySQLiteDatabase = db.getWritableDatabase();Log.i(数据库对象。
DATABASE_NAME, SQL);} catch (SQLException e) {e.printStackTrace();Log.i(创建表--》,就调用该方法 */@Overridepublic void onCreate(SQLiteDatabase db) {Log.i(createDatabases, 1);mySQLiteDatabase = db.getWritableDatabase();ContentValues cv = new ContentValues();cv.put(username, null, 涉及SQLite的增删改查。
null, num + );mySQLiteDatabase.close();break;}default:break;}}}RelativeLayout xmlns:android=xmlns:tools=android:layout_width=match_parentandroid:layout_height=match_parentandroid:paddingBottom=@dimen/activity_vertical_marginandroid:paddingLeft=@dimen/activity_horizontal_marginandroid:paddingRight=@dimen/activity_horizontal_marginandroid:paddingTop=@dimen/activity_vertical_margintools:context=com.example.sqlconnecttest.MainActivity TextViewandroid:id=@+id/textViewandroid:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:text=SQLite数据库/Buttonandroid:id=@+id/createDatabaseandroid:layout_width=fill_parentandroid:layout_height=wrap_contentandroid:layout_below=@id/textViewandroid:text=创建一个数据库/Buttonandroid:id=@+id/createTableandroid:layout_width=fill_parentandroid:layout_height=wrap_contentandroid:layout_below=@id/createDatabaseandroid:text=创建一张表/Buttonandroid:id=@+id/insertandroid:layout_width=fill_parentandroid:layout_height=wrap_contentandroid:layout_below=@id/createTableandroid:text=插入数据/Buttonandroid:id=@+id/selectandroid:layout_width=fill_parentandroid:layout_height=wrap_contentandroid:layout_below=@id/insertandroid:text=查询数据/Buttonandroid:id=@+id/updateandroid:layout_width=fill_parentandroid:layout_height=wrap_contentandroid:layout_below=@id/selectandroid:text=更新数据/Buttonandroid:id=@+id/deleteandroid:layout_width=fill_parentandroid:layout_height=wrap_contentandroid:layout_below=@id/updateandroid:text=删除数据//RelativeLayout 运行结果 , DATABASE_NAME。
password, 1);mySQLiteDatabase = db.getWritableDatabase();ContentValues cv1 = new ContentValues();cv1.put(username, admin);cv1.put(phoneNumber, null, whereArgs1);Log.i(删除记录--, +[username] VARCHAR NOT NULL, factory, DATABASE_NAME, cv);Log.i(插入数据, 1);mySQLiteDatabase = db.getWritableDatabase();try {mySQLiteDatabase.execSQL(SQL);Log.i(创建表, 创建数据库---);}/* * 当更新数据库时, null, String name,null,null, CursorFactory factory, index + );break;}case R.id.delete:{db = new DBHelper(MainActivity.this, 老爸);cv.put(password, 1388888);String whereClause = id + =http://www.it165.net/database/html/201501/?;String[] whereArgs = {8};/** 参数1:表名* 参数2:是一个ContextValue对象, DATABASE_NAME。
+[password] VARCHAR NOT NULL。
mySQLiteDatabase.toString());//System.out.print(数据库对象+mySQLiteDatabase);break;}case R.id.createTable:{db = new DBHelper(MainActivity.this,调用该方法 */@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, null,结果用log显示 package com.example.sqlconnecttest;import android.content.Context;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteDatabase.CursorFactory;import android.database.sqlite.SQLiteOpenHelper;import android.util.Log;public class DBHelper extends SQLiteOpenHelper{/* * 必须有的构造器 */public DBHelper(Context context, null, admin);cv1.put(password, 1);mySQLiteDatabase = db.getReadableDatabase();/*** 参数1:表名* 参数2:要显示的列* 参数3:where语句* 参数4:where语句的条件值* 参数5:分组方式* 参数6:having条件* 参数7:排序方式*/Cursor cursor = mySQLiteDatabase.query(TABLE_NAME, null);while(cursor.moveToNext()){int id = cursor.getInt(cursor.getColumnIndex(id));String username = cursor.getString(cursor.getColumnIndex(username));String password = cursor.getString(cursor.getColumnIndex(password));String phoneNumber = cursor.getString(cursor.getColumnIndex(phoneNumber));Log.i(query--,就是更新的值* 参数3:where语句条件* 参数4:where条件的值*/int index = mySQLiteDatabase.update(TABLE_NAME, null, 134756658888);long n = mySQLiteDatabase.insert(TABLE_NAME, 更新数据库---);}}package com.example.sqlconnecttest;import android.app.Activity;import android.content.ContentValues;import android.database.Cursor;import android.database.SQLException;import android.database.sqlite.SQLiteDatabase;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity implements OnClickListener{private Button createDatabase;private Button createTable;private Button insert;private Button select;private Button update;private Button delete;private final String DATABASE_NAME = myDatabase;private SQLiteDatabase mySQLiteDatabase = null;private final String TABLE_NAME = user;private String SQL =CREATE TABLE [user] (+[id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, int newVersion) {Log.i(updateDatabase, n + );mySQLiteDatabase.close();break;}case R.id.select:{db = new DBHelper(MainActivity.this, 创建表失败----------------》);}break;}case R.id.insert:{db = new DBHelper(MainActivity.this,DATABASE_NAME,int version) {super(context, DATABASE_NAME, id: + id + userName: + username +password + password + phoneNumber + phoneNumber);}mySQLiteDatabase.close();break;}case R.id.update:{db = new DBHelper(MainActivity.this。
phoneNumber}, cv1, whereArgs);Log.i(update--,username, whereClause。
1);mySQLiteDatabase = db.getWritableDatabase();/**** 参数1:表名* 参数2:where语句字段* 参数3:where语句字段的值*/String whereClause1 = id + =http://www.it165.net/database/html/201501/?;String[] whereArgs1 = {1};int num = mySQLiteDatabase.delete(TABLE_NAME,new String[]{id。
123456);cv.put(phoneNumber。
null,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/sql/sqlite/11349.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
sqlite只通过文件锁就可以
时间:2021-01-23
-
返回的是一个SQLiteDatabas
时间:2021-01-23
-
只不过它是OC方式封装了
时间:2021-01-23
-
应该增加autoincrementcreate
时间:2021-01-23
-
如果没有就从Bundle中把数
时间:2021-01-23
-
Linux 部署ASP.NET SQLite 应用
时间:2021-01-23
-
只有被 sqlite3_bind_value()和
时间:2021-01-23
-
iOS开拓之SQLiteC语言接口类
时间:2021-01-23
热门文章
-
11SQLite之view(视图)
时间:2021-01-05
-
解压后拷贝出sqlite3文件到便于CMD命令行便
时间:2021-01-16
-
SQLite的架构(TheArchitectureOfSQLite)
时间:2021-01-05
-
只有被 sqlite3_bind_value()和sqlite3_result_val
时间:2021-01-23
-
应该增加autoincrementcreate table t_student (id
时间:2021-01-23
-
Android数据存储的三种方法SharedPrefrences
时间:2021-01-16
-
Android数据存储三剑客SharedPreferences File
时间:2021-01-07
-
sQlite常用语句以及sQlite developer的使用与注
时间:2020-12-24
-
3.2基于MBTiles规范进行存储 设计思路为:
时间:2021-01-13
-
SQLite数据库管理系统-我所认识的数据库引
时间:2020-12-28
